package day13.XianCheng;

import DiTie.Manager;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Lian11 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        method1();

//        method2();
        Mycallable mc=new Mycallable();
        FutureTask<String>f=new FutureTask<>(mc);
        Thread t1=new Thread(f);
        t1.start();
        String s = f.get();
        System.out.println(s);
    }

    private static void method2() {
        MyRunable mr=new MyRunable();
        Thread s1=new Thread(mr);
        Thread s2=new Thread(mr);
        s1.start();
        s2.start();
    }

    private static void method1() {
        MyThread t1 = new MyThread();
        MyThread t2 = new MyThread();
        t1.start();
        t2.start();
    }
}

class MyThread extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println("干活" + i);
        }
    }
}

class MyRunable implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println("吃饭"+i);
        }
    }
}

class Mycallable implements Callable<String>{

    @Override
    public String call() throws Exception {
        for (int i = 0; i < 100; i++) {
            System.out.println("求婚"+i);
        }
        return "答应你";
    }
}
